﻿using ArtMath.Core.Data;
using ArtMath.Core.Helper;
using System;

namespace ArtMath.PointCollection
{
    [Serializable]
    public class StraightLineOneSide : ContinuityPoint
    {
        //public enum DirectionOptions
        //{
        //    AboveOrRight,
        //    AboveOrRight_IncludeLine,
        //    BelowOrLeft,
        //    BelowOrLeft_IncludeLine,
        //}
        public PointD Location, RefPoint;
        public double Slope;
        //public DirectionOptions Direction;
        public StraightLineOneSide()
        {

        }
        public StraightLineOneSide(PointD location, double k, PointD refpt)
        {
            Location = location;
            Slope = k;
            RefPoint = refpt;
        }
        public override bool Contains(PointD pt)
        {
            return Utility.OnSameSide(Location, Slope, RefPoint, pt) && AfterContains(pt);
        }
        //bool inRegion(PointD pt)
        //{
        //    int sign = pt.WhereStraightLine(Location, Slope);
        //    if (sign == 0)
        //    {
        //        return Direction == DirectionOptions.AboveOrRight_IncludeLine || Direction == DirectionOptions.BelowOrLeft_IncludeLine;
        //    }
        //    else
        //    {
        //        return (Direction == DirectionOptions.AboveOrRight || Direction == DirectionOptions.AboveOrRight_IncludeLine) && sign > 0 ||
        //            (Direction == DirectionOptions.BelowOrLeft || Direction == DirectionOptions.BelowOrLeft_IncludeLine) && sign < 0;
        //    }
        //}
        public override PointD? GetNearestPoint(PointD pt)
        {
            if (Utility.OnSameSide(Location, Slope, RefPoint, pt)) return pt;
            return pt.GetProjectivePoint(Location, Slope);
        }

        protected override PointCollectionBase Intersect(PointCollectionBase collection)
        {
            return CustomIntersect(collection);
        }
    }
}
